import pandas as pd

comments = pd.read_csv(f'../data_csv/comment/reviews.csv')
product_id = []
good_rate = []
medium_rate = []
bad_rate = []
# 循环遍历每一行
for index, row in comments.iterrows():
    # 读取每一行的第一、二、三和四列数据
    Product_ID = row.iloc[0]  # 第一列数据
    Positive_Reviews = row.iloc[1]  # 第二列数据
    Neutral_Reviews = row.iloc[2]  # 第三列数据
    Negative_Reviews = row.iloc[3]  # 第四列数据

    Reviews_Sum = Positive_Reviews + Neutral_Reviews + Negative_Reviews
    good = Positive_Reviews / Reviews_Sum
    medium = Neutral_Reviews / Reviews_Sum
    bad = Negative_Reviews / Reviews_Sum

    product_id.append(Product_ID)
    good_rate.append(good)
    medium_rate.append(medium)
    bad_rate.append(bad)

evaluation = {
    'product_id': product_id,
    'good_rate': good_rate,
    'medium_rate': medium_rate,
    'bad_rate': bad_rate
}

df = pd.DataFrame(evaluation)
df.to_csv(f'../data_csv/comment/evaluation.csv',index=False)
